package com.itheima.controller;

import com.itheima.project.costomannotation.log ;
import com.itheima.project.PageBean;
import com.itheima.project.Result;
import com.itheima.project.student.Student;
import com.itheima.project.student.StudentQueryParam;
import com.itheima.filter.service.inter.StudentService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/students")
@RestController
public class StudentController {
    @Resource
    private StudentService studentService;

    @GetMapping
    public Result page(StudentQueryParam sqp) {
        log.info("学生分页查询" + sqp.toString());
        PageBean pageBean = studentService.page(sqp);
        return Result.success(pageBean);
    }
    @log
    @DeleteMapping("/{ids}")
    public Result deletById(@PathVariable List<Integer> ids) {
        log.info("根据id删除学生" + ids.toString());
        studentService.deletById(ids);
        return Result.success();
    }
    @log
    @PostMapping
    public Result saveStudent(@RequestBody Student student) {
        log.info("添加学生" + student);
        studentService.saveStudent(student);
        return Result.success();
    }
    @log
    @PutMapping
    public Result modifyStudent(@RequestBody Student student) {
        log.info("修改学生信息" + student);
        studentService.modifyStudent(student);
        return Result.success();
    }

    //编辑回显
    @GetMapping("/{id}")
    public Result queryStudentById(@PathVariable Integer id) {
        log.info("根据id查询学生" + id);
        Student student = studentService.queryStudentById(id);
        return Result.success(student);
    }
    @log
    @PutMapping("/violation/{id}/{score}")
    public Result Disciplinaryaction(@PathVariable Integer id,
                                     @PathVariable Integer score) {
        log.info("学生违纪处理" + id + score);
        studentService.Disciplinaryaction(id, score);
        return Result.success();
    }
}
